package com.wzy.pipeline;

import lombok.Data;

/**
 * @Auther: wzy
 * @Date: 2021/12/11/10:15
 * @Description:
 */
@Data
public class CommonResponse<T> {
    private Long code;
    private String message;
    private T data;

    /**
     * 成功，无返回
     *
     * @return Result
     **/
    public static CommonResponse success() {
        return success(null, null);
    }

    /**
     * 成功，返回结果
     *
     * @param data 泛型结果
     * @return Result
     **/
    public static <T> CommonResponse success(T data, Long code) {
        CommonResponse<T> result = new CommonResponse<>();
        result.setCode(code);
        result.setMessage("success");
        result.setData(data);
        return result;
    }

    /**
     * 成功，返回结果
     *
     * @param message 正确信息
     * @return Result
     **/
    public static CommonResponse success(String message) {
        CommonResponse result = new CommonResponse<>();
        result.setCode(200L);
        result.setMessage(message);
        return result;
    }

    public static CommonResponse failure(String s) {
        CommonResponse result = new CommonResponse<>();
        result.setCode(404L);
        result.setMessage(s);
        return result;
    }

    public static CommonResponse<Long> failed(String errorMsg) {
        CommonResponse result = new CommonResponse<>();
        result.setCode(404L);
        result.setMessage(errorMsg);
        return result;
    }
}
